<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="CommonUtil/CommonUtil.js"></script>
    <script type="text/javascript" charset="utf-8">
        /**
         * 责任链模式
         * 目的：处理发出者和接受者之间的耦合
         * 做项目->项目经理：->task 项目组：[小A，小B，小C，小D]
         * 接收任务的类
         */
        var Assign = function (task) {
            this.task = task;
        };
        //接收任务的类
        var WorkFlow = function (assign) {
            this.assign = assign;
         };
        WorkFlow.prototype = {
            constructor:WorkFlow,
            filterHandle:function (executor) {
                if(this.assign.task === executor.cando){
                    return executor.todo();
                }else{
                    arguments.callee.call(this,executor.successor);
                }

            }
        }
        //处理者
        var Executor = function (name,cando) {
            this.name = name;
            this.cando = cando;
            //保留当前接受者的下一个对象的引用
            this.successor = null;
        };
        Executor.prototype = {
            constructor:Executor,
            todo:function () {
                document.write(this.name+'开发：'+this.cando);
            },
            //设置责任链的配置函数
            setSuccessor:function (successor) {
                this.successor = successor;
            }
        }
        //实例4个处理对象
        var e1 = new Executor('小A','javascript编程');
        var e2 = new Executor('小B','css编程');
        var e3 = new Executor('小C','java编程');
        var e4 = new Executor('小D','sql编程');
        e1.setSuccessor(e2);
        e2.setSuccessor(e3);
        e3.setSuccessor(e4);
        //实例化任务对象
        var assign =  new Assign('java编程');
        //处理任务类的实例
        var wf = new WorkFlow(assign);
        wf.filterHandle(e1);
    </script>
</head>
<body>
</body>
</html>